<?php

namespace App\Domain\Role\Controllers;

use App\Domain\Role\Requests\RolePost;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Spatie\Permission\Models\Role;
use App\Domain\Role\Services\RoleService;


class RoleController extends Controller
{

    /**
     * 角色列表
     */
    public function list(RoleService $roleService)
    {
        $data = $roleService->list();
        return $this->success($data);
    }


    /**1,
     * 修改角色及其权限
     * @param RolePost $request
     * @return mixed
     * @throws \Exception
     */
    public function update(RolePost $request, RoleService $roleService)
    {
        $params = [
            'role_id' => $request->input('roleId'),

            'show_name' => $request->input('roleName'),//角色名称

            'describe' => $request->input('describe'),//角色描述
            'permission_ids' => $request->input('jurisdiction'),//权限

        ];
        $data = $roleService->update($params);
        return $this->success($data);
    }

    /**
     * 删除角色
     * @param Request $request
     * @return mixed
     */
    public function delete(Request $request, RoleService $roleService)
    {
        $this->validate($request, [
            'roleId' => 'required|numeric',
        ]);
        $data = $roleService->delete($request->input('roleId'));
        return $this->success($data);
    }
}
